/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package my.presentation;

import app.Autentizace;
import entities.Uzivatel;
import javax.ejb.EJB;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author acer
 */
@ManagedBean(name = "PrihlaseniView")
@SessionScoped
public class PrihlaseniView {
    
    @EJB
    private Autentizace auth;
    
    private boolean logged; 
    
    private String username;
    private String password;
    
    private String celejmeno;


    public Autentizace getAuth() {
        return auth;
    }

    public String getCeleJmeno() {
        return celejmeno;
    }

    public void setCeleJmeno(String celejmeno) {
        this.celejmeno = celejmeno;
    }
    
    public boolean isLogged() {
        return logged;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public PrihlaseniView() {
        logged = false;
        username = celejmeno = password = "";
    }
    
    //kliknuti na Prihlasit se
    public void submitLogin(){
        Uzivatel user = null;
        try {
            user = auth.prihlasitSe(username, password);
        } catch (Exception e) {
            e.printStackTrace();
            
        }
        
        if (user == null){
            logged = false;
            password = "";
        } else {
            logged = true;
        }
    }
    
    //kliknuti na Odhlasit se
    public void unlog(){
        username = "";
        password = "";
        logged = false;
    }
   
}
